//
//  XYTSelectButton.m
//  XYTPayOrderSystem
//
//  Created by wupeng on 2017/9/11.
//  Copyright © 2017年 wupeng. All rights reserved.
//

#import "XYTSelectButton.h"

@implementation XYTSelectButton

- (instancetype)initWithFrame:(CGRect)frame buttonTitle:(NSString *)title{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor clearColor];
        self.title = title;
        [self setupUI:title];
    }
    return self;
}

- (void)setupUI:(NSString *)title{
    UIButton *selecteButton = [[UIButton alloc] initWithFrame:CGRectMake(1, (boundsHeight-15)*0.5, 15, 15)];
    [selecteButton setImage:[UIImage imageNamed:@"treatyNotSeleced"] forState:UIControlStateNormal];
    [selecteButton setImage:[UIImage imageNamed:@"treatySeleced"] forState:UIControlStateSelected];
    [selecteButton addTarget:self action:@selector(selecteButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    selecteButton.selected = NO;
    [self addSubview:selecteButton];
    self.selectedButton = selecteButton;
    
    UILabel *desLab = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(selecteButton.frame)+5, (boundsHeight-15)*0.5, boundsWidth-(CGRectGetMaxX(selecteButton.frame)+5) , 15)];
    desLab.font = [UIFont systemFontOfSize:12];
    desLab.textColor = [UIColor colorWithRed:69.0f/255.0 green:140.0f/255.0 blue:200.0f/255.0 alpha:1];
    desLab.text = title;
    [self addSubview:desLab];
    self.desLab = desLab;
}

- (void)setTitle:(NSString *)title{
    self.desLab.text = title;
}

- (void)setSelected:(BOOL)selected{
    self.selectedButton.selected = selected;
}

- (void)selecteButtonClick:(UIButton *)button{
    
    self.selected = button.selected ? NO : YES;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
